/**
 * Created by Administrator on 2017/9/21 0021.
 */
import React from "react";
import { Tree } from 'antd';
const TreeNode = Tree.TreeNode;

class TreeSelectComponent extends React.Component {

    onCheck = (checkedKeys, info) => {
        this.props.getId(checkedKeys);
    }
    render() {
        return (
            <Tree
                checkable
                defaultExpandedKeys={this.props.defaultArr}
                defaultCheckedKeys={this.props.defaultArr}
                onCheck={this.onCheck}
            >
                {
                    this.props.data.map((ele)=>{
                        if (ele.children && ele.children.length){
                            return (
                                <TreeNode title={ele.name} key={ele.id}>
                                    {
                                        ele.children.map((child)=>   <TreeNode title={child.name} key={child.id} />)
                                    }
                                </TreeNode>
                            )
                        }else {
                            return <TreeNode title={ele.name} key={ele.id}></TreeNode>
                        }
                    })
                }
            </Tree>
        );
    }
}


export default TreeSelectComponent;